package com.henry.controller;

import com.henry.bean.MsgDTO;
import com.henry.enums.RoutingKeyName;
import com.henry.producer.MsgProducer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class ProducerController {

    @Resource
    private MsgProducer msgProducer;

    @GetMapping("test")
    public String test() {
        return "hello rabbitmq this is producer";
    }

    @GetMapping("directSendMsg")
    public void sendMsg() {
        MsgDTO msgDTO = new MsgDTO();
        msgDTO.setMsgId("1");
        msgDTO.setContent("i'm shelby");
        msgProducer.directSendMsg(msgDTO);
    }

    @GetMapping("topicSendMsg")
    public void topicMsg() {
        //发送短信
        MsgDTO msgDTO = new MsgDTO();
        msgDTO.setMsgId("1");
        msgDTO.setContent("短信信息");
        msgProducer.topicSendMsg(msgDTO, RoutingKeyName.TOPIC_MSG_ROUTING_KEY_SMS.name());
        //发送邮件信息
        MsgDTO email = new MsgDTO();
        email.setMsgId("2");
        email.setContent("邮件信息");
        msgProducer.topicSendMsg(email, RoutingKeyName.TOPIC_MSG_ROUTING_KEY_EMAIL.name());
    }

}
